package com.star.comtroller;

import com.star.entry.Benefit;
import com.star.entry.Post;
import com.star.service.BenefitService;
import com.star.service.PostService;
import com.star.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@SuppressWarnings("all")
@RestController
@RequestMapping("/post/")
public class PostController {

    @Autowired
    private BenefitService benefitService;
    @Autowired
    private PostService postService;
    @Autowired
    private ResultObject result;

    @RequestMapping("findByEid")
    public ResultObject findByEid(int eid){
        result.setStatus(400);
        result.setResult(postService.selectByEid(eid));

        return result;
    }
    @RequestMapping("findAllBenefit")
    public ResultObject findAllBenefit(int pid){
        result.setStatus(400);
        ArrayList<Benefit> benefits = benefitService.selectByPid(pid);
        result.setResult(benefits);
        return result;
    }
    @RequestMapping("findById")
    public ResultObject findById(int id){
        result.setStatus(400);
        result.setResult(postService.selectById(id));
        return result;
    }
    @RequestMapping("findByType")
    public ResultObject findByType(String type){
        result.setStatus(400);
        result.setResult(postService.selectByType(type));
        return  result;
    }
    @RequestMapping("findBySalary")
    public  ResultObject findBySalary(Double salary){
        result.setStatus(400);
        result.setResult(postService.selectBySalary(salary));
        return result;
    }
    @RequestMapping("find")
    public ResultObject find(Post post){
        result.setStatus(400);
        result.setResult(postService.select(post));
        return result;
    }
    @RequestMapping("changeApply")
    public ResultObject changeApply(Post post){
        boolean b = postService.changeApply(post);
        if (b){
            result.setStatus(400);
            result.setResult("修改成功");
        }else {
            result.setStatus(408);
            result.setResult("修改失败");
        }
        return result;
    }

}
